﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Media3D;
using System.Xml.Serialization;

namespace CoreModule
{
    /// <summary>
    ///  界面 配置
    /// </summary>
    public class FunctionCheckConfigurationInfo
    {

        /// <summary>
        /// 有条目 选择
        /// </summary>
        /// 
        [System.Xml.Serialization.XmlIgnore()]
        public bool AnyCheck
        {
            get
            {
                return RespiratoryRate
                    | Pain
                    | BloodSugar
                    | Height_Weight_BMI
                    | EWS
                    | Consciousness
                    | MobilePhone;
            }
            set
            {

            }
        }


        [System.Xml.Serialization.XmlIgnore()]
        public Visibility AnyCheckVisibility
        {
            get
            {
                return AnyCheck ? Visibility.Visible : Visibility.Collapsed;
            }
            set
            {

            }
        }

        [System.Xml.Serialization.XmlIgnore()]
        public Visibility AnyCheckVisibilityHidden
        {
            get
            {
                return AnyCheck ? Visibility.Visible : Visibility.Hidden;
            }
            set
            {

            }
        }

        static string XmlFilePath = "FunctionCheckConfigurationInfo.xml";
        /// <summary>
        /// 呼吸率
        /// </summary>
        public bool RespiratoryRate { get; set; } = true;

        [System.Xml.Serialization.XmlIgnore()]
        public Visibility RespiratoryRateVisibility
        {
            get
            {
                return RespiratoryRate ? Visibility.Visible : Visibility.Collapsed;
            }
            set
            {

            }
        }

        /// <summary>
        /// 疼痛
        /// </summary>
         public bool Pain { get; set; } = true;     

        [System.Xml.Serialization.XmlIgnore()]
        public Visibility PainVisibility
        {
            get
            {
                return Pain ? Visibility.Visible : Visibility.Collapsed;
            }
            set
            {

            }
        }
        /// <summary>
        /// 血糖
        /// </summary>
        public bool BloodSugar { get; set; } = true;

        [System.Xml.Serialization.XmlIgnore()]
        public Visibility BloodSugarVisibility
        {
            get
            {
                return BloodSugar ? Visibility.Visible : Visibility.Collapsed;
            }
            set
            {

            }
        }
        /// <summary>
        /// 身高，体重、BMI
        /// </summary>
        public bool Height_Weight_BMI { get; set; } = true;

        [System.Xml.Serialization.XmlIgnore()]
        public Visibility Height_Weight_BMIVisibility
        {
            get
            {
                return Height_Weight_BMI ? Visibility.Visible : Visibility.Collapsed;
            }
            set
            {

            }
        }
        /// <summary>
        /// ESW
        /// </summary>
        public bool EWS { get; set; } = true;

        [System.Xml.Serialization.XmlIgnore()]
        public Visibility EWSVisibility
        {
            get
            {
                return EWS ? Visibility.Visible : Visibility.Collapsed;
            }
            set
            {

            }
        }
        /// <summary>
        /// 意识
        /// </summary>
        public bool Consciousness { get; set; } = true;

        [System.Xml.Serialization.XmlIgnore()]
        public Visibility ConsciousnessVisibility
        {
            get
            {
                return Consciousness ? Visibility.Visible : Visibility.Collapsed;
            }
            set
            {

            }
        }
        /// <summary>
        /// 手机号
        /// </summary>
        public bool MobilePhone { get; set; } = true;

        [System.Xml.Serialization.XmlIgnore()]
        public Visibility MobilePhoneVisibility
        {
            get
            {
                return MobilePhone ? Visibility.Visible : Visibility.Collapsed;
            }
            set
            {

            }
        }

        public static FunctionCheckConfigurationInfo Load()
        {
            if (File.Exists(XmlFilePath))
            {
                try
                {
                    using (FileStream fileStream = new FileStream(XmlFilePath, FileMode.OpenOrCreate))
                    {
                        var conf = (FunctionCheckConfigurationInfo)new XmlSerializer(typeof(FunctionCheckConfigurationInfo)).Deserialize(fileStream);
                        return conf;
                    }
                }
                catch (Exception)
                {
                    File.Delete(XmlFilePath);
                    return new FunctionCheckConfigurationInfo();
                }
            }
            return new FunctionCheckConfigurationInfo();

        }


        /// <summary>
        /// /
        /// </summary>
        public void Save()
        {
            if (File.Exists(XmlFilePath))
            {
                File.Delete(XmlFilePath);
            }
            try
            {
                using (FileStream fileStream = new FileStream(XmlFilePath, FileMode.OpenOrCreate))
                {
                    new XmlSerializer(typeof(FunctionCheckConfigurationInfo)).Serialize(fileStream, this);
                }
            }
            catch (Exception)
            {
            }
        }

    }
}
